import { createApp } from 'vue';
import App from '@/App.vue';
import '@/styles/reset-element.scss';
import '@/styles/global.scss';
import ElementPlus from 'element-plus';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import router from '@/router';
import { store, zwScrm } from '@/store';
import '@/router/permission';
import Bus from '@/utils/bus';
import { auth } from '@/utils/utils';
import ZWPower from '@/components/ZWPower.vue';
import directives from './utils/directives';

import tableHeaderTooltip from './view/ecommerce/components/tableHeaderTooltip.vue';
import elPopoverTips from './view/member/memberManage/memberList/detail/components/elPopoverTips.vue';
import tableTooltip from './view/ecommerce/components/tableTooltip.vue';
import tablePopover from './view/ecommerce/userManage/userRecipientsList/components/tablePopover.vue';
import tableHeaderPopover from './view/ecommerce/components/tableHeaderPopover.vue';
import ArticleDetail from '@/components/common/ArticleDetail.vue';

import apiRoot from '@/utils/domain';

import ZwUnitykitSelectItems from '@zhongwan/zw-unitykit-select-items';

import { AtomScrmUI } from '@zhongwan/atom';

const app = createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}

app.component('ZwPower', ZWPower)
    .component('tableHeaderTooltip', tableHeaderTooltip)
    .component('tableTooltip', tableTooltip)
    .component('tablePopover', tablePopover)
    .component('ArticleDetail', ArticleDetail)
    .component('tableHeaderPopover', tableHeaderPopover)
    .component('elPopoverTips', elPopoverTips);

// 使用自定义指令
Object.keys(directives).forEach((item: any) => {
    app.directive(item, directives[item]);
});

app.use(AtomScrmUI);
app.use(ZwUnitykitSelectItems, {
    domainApi: apiRoot?.BASE_API_URL
});

app.config.globalProperties.$bus = Bus;
app.config.globalProperties.$auth = auth;
app.config.warnHandler = () => null;
app.use(store, zwScrm).use(ElementPlus, { sizi: 'default' }).use(router).mount('#app');
